import "package:ct_pa_majordomo/utils/request.dart";
import "package:ct_pa_majordomo/utils/storage.dart";
import "package:dio/dio.dart";

class UserApi {
  Future<void> login(data) async {
    Response response = await request.post("tai-auth/login", data: data);
    storage.setString("token", response.data["data"]?["access_token"] ?? "");
  }

  Future<void> register(data) async {
    Response response = await request.post("tai-auth/register", data: data);
    return response.data ?? {};
  }

  Future<Map> getInfo() async {
    Response response = await request.get("apartment/member/getInfo");
    return response.data ?? {};
  }

  Future<Map> updateInfo(data) async {
    Response response = await request.put("apartment/member", data: data);
    return response.data ?? {};
  }

  /* 修改个人信息 */
  Future<Map> updateProfile(data) async {
    Response response = await request.post("apartment/member/update-profile", data: data);
    return response.data ?? {};
  }

  // 原系统退出登录
  Future<Map> logout() async {
    Response response = await request.delete("auth/logout");
    return response.data ?? {};
  }

  /* 修改密码 */
  Future<Map> updatePwd(data) async {
    Response response = await request.post("apartment/member/update-password",
      data: data
    );
    return response.data ?? {};
  }
}

UserApi userApi = UserApi();
